/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.repository.adaptor.method;

//import Inspur.Gsp.Caf.Generator.BaseInfoItem.*;
//import Inspur.Gsp.Caf.Generator.ClassMethodGenerator.*;
//import Inspur.Gsp.Caf.Generator.Utils.*;
//import Inspur.Gsp.Cef.Repository.*;
//import Microsoft.CodeAnalysis.*;
//import Microsoft.CodeAnalysis.CSharp.*;
//import Microsoft.CodeAnalysis.CSharp.Syntax.*;

import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.api.repository.IRootRepository;
import com.inspur.edp.cef.designtime.api.IGspCommonField;
import com.inspur.edp.cef.generator.repository.AssemblerInfo;
import com.inspur.edp.cef.repository.assembler.AssociationInfo;
import com.inspur.edp.cef.repository.assembler.DataTypeAssembler;
import com.inspur.edp.cef.repository.assembler.LogicDeleteInfo;
import com.inspur.edp.cef.repository.assembler.entity.MainEntityAssembler;
import lombok.var;
import org.eclipse.jdt.core.dom.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GetLogicDeleteInfoGenerator extends ClassMethodGenerator {
	private LogicDeleteInfo logicDeleteInfo;
	private GspBizEntityObject gspBizEntityObject;

	public GetLogicDeleteInfoGenerator(GspBizEntityObject gspBizEntityObject) {
		this.gspBizEntityObject = gspBizEntityObject;
		if(gspBizEntityObject.getLogicDeleteControlInfo() == null){
			this.logicDeleteInfo = new LogicDeleteInfo(false, "");
		}
		else{
			String logicDelLabel = "";
			for(IGspCommonField field:gspBizEntityObject.getContainElements()){
				if(field.getID().equals(gspBizEntityObject.getLogicDeleteControlInfo().getLogicDeleteControlElementId() == null ? "" :gspBizEntityObject.getLogicDeleteControlInfo().getLogicDeleteControlElementId())){
					logicDelLabel = field.getLabelID();
					break;
				}
			}
			this.logicDeleteInfo = new LogicDeleteInfo(gspBizEntityObject.getLogicDeleteControlInfo().getEnableLogicDelete(), logicDelLabel);
		}
	}

	//#region Impl

	@Override
	protected boolean getIsOverride() {
		return true;
	}

	@Override
	protected String getMethodName() {
		return "getLogicDeleteInfo";
	}

	@Override
	protected TypeInfo getReturnType() {
		return new TypeInfo(LogicDeleteInfo.class.getTypeName());
	}

	@Override
	protected ArrayList<Modifier.ModifierKeyword> getAccessModifiers() {
		ArrayList<Modifier.ModifierKeyword> list = new ArrayList<Modifier.ModifierKeyword>();
		list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
		return list;
	}

	@Override
	protected ArrayList<ParameterInfo> getParameterCollection() {
		return null;
	}

	@Override
	protected Block buildMethodBody() {
		addImport(LogicDeleteInfo.class.getTypeName());
		Block block = ast.newBlock();
		var returnStatement = ast.newReturnStatement();

		ClassInstanceCreation classInstanceCreation = ast.newClassInstanceCreation();
		classInstanceCreation.setType(ast.newSimpleType(ast.newSimpleName("LogicDeleteInfo")));
		classInstanceCreation.arguments().add(ast.newBooleanLiteral(this.logicDeleteInfo.isEnableLogicDelete()));
		StringLiteral valueLiteral = ast.newStringLiteral();
		valueLiteral.setLiteralValue(this.logicDeleteInfo.getLabelId());
		classInstanceCreation.arguments().add(valueLiteral);
		returnStatement.setExpression(classInstanceCreation);
		block.statements().add(returnStatement);
		return block;
	}


//#endregion
}
